/*
 * @Author: 0x9DEFA478
 * @Date: 2024-07-29 17:34:45
 * @LastEditTime: 2024-07-29 18:12:08
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * QQ:2652450237
 * ============================================================================================================================================
 * 
 * 
 * 
 *                                                                                               ************      ****************************
 *                                                                                             ************      ****************************  
 *                                                                                           ************      ****************************    
 *                                                                                         ************      ****************************      
 *                                                                                       ************      ************                        
 *                                                                                     ************      ************                          
 *                                                                                   ************      ************                            
 *                                                                                 ************      ************                              
 *                                                                               ************      ************                                
 *                                                                             ************      ************                                  
 *                                                                           ************      ************                                    
 *                                                                         ************      ************                                      
 *                                                                       ************      ************                                        
 *                                                                     ************      ************                                          
 *                                                                   ************      ************                                            
 *                                                                 ************      ************                                              
 *                                                               ************      ************                                                
 *                                                             ************      ************                                                  
 *                                                           ************      ************                                                    
 *                                                         ************      ************                                                      
 *                                                       ************      ************                                                        
 *                                                     ************      ************                                                          
 *                                                   ************      ************                                                            
 *                                                 ************      ************                                                              
 *                                               ************      ************                                                                
 *                                             ************      ************                                                                  
 *                                           ************      ************                                                                    
 *                                         ************      ************                                                                      
 *                                       ************      ************                                                                        
 *                                     ************      ************                                                                          
 *                                   ************      ************                                                                            
 *                                 ************      ************                                                                              
 *                               ************      ************                                                                                
 *                             ************      ************                                                                                  
 *                           ************      ************                                                                                    
 *                         ************      ************                                                                                      
 *       ****************************      ************                                                                                        
 *     ****************************      ************                                                                                          
 *   ****************************      ************                                                                                            
 * ****************************      ************                                                                                              
 * 
 * 
 * 
 * ============================================================================================================================================
 * 
 */
#include "./H_TS_Lock.h"
#include "../LL/H_TS_LL.h"




void H_TS_Lock_Init(H_TS_Lock* Lock){
  oH_TS_Assert_HandleValid(Lock==NULL,"H_TS:H_TS_Lock_Init():空的句柄");
  Lock->Owner=NULL;
  Lock->ReLockCnt=0;
  Lock->WaitLockThreads=NULL;
}

int H_TS_Lock_Deinit(H_TS_Lock* Lock){
  int r;
  
  oH_TS_Assert_HandleValid(Lock==NULL,"H_TS:H_TS_Lock_Deinit():空的句柄");

  r=0;

  oH_TS_LL_SchedulerSuspend();

  if(Lock->Owner!=NULL){
    r=-1;
  }

  oH_TS_LL_ResumeSchedulerAuto();
  return r;
}

H_TS_Lock* new_H_TS_Lock(){
  H_TS_Lock* r;

  oH_TS_LL_SchedulerSuspend();
  r=H_TS_LL_Core_Instance.Memory.Malloc(sizeof(H_TS_Lock));
  oH_TS_LL_ResumeSchedulerAuto();
  if(r==NULL){
    return r;
  }

  H_TS_Lock_Init(r);

  return r;
}

int delete_H_TS_Lock(H_TS_Lock* Lock){

  if(0!=H_TS_Lock_Deinit(Lock)){
    return -1;
  }

  oH_TS_LL_SchedulerSuspend();
  H_TS_LL_Core_Instance.Memory.Free(Lock);
  oH_TS_LL_ResumeSchedulerAuto();

  return 0;
}



